package com.woniu.utils;

import cn.hutool.core.util.RandomUtil;
import com.woniu.vo.RandomNumberVO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 机选工具类
 */
@Component
public class LuckRandomUtils {

    /**
     *
     * @param number 机选数量
     * @param count 3D和PL3都是3，PL5是5
     * @return
     */
    public List<RandomNumberVO> random3Dor3or5(int number, int count) {
        List<RandomNumberVO> result = new ArrayList<>();
        for (int i = 0; i < number; i++) {

            List<String> fcList = new ArrayList<>();

            for (int j = 0; j < count; j++) {
                fcList.add(String.valueOf(RandomUtil.randomInt(0, 10)));
            }

            String left = fcList.stream().map(String::valueOf).collect(Collectors.joining(","));

            //String reds = String.join(",", redList);
            result.add(RandomNumberVO.builder().left(left).build());
        }

        return result;
    }

    public List<RandomNumberVO> randomQXC(int number) {
        List<RandomNumberVO> result = new ArrayList<>();
        for (int i = 0; i < number; i++) {

            List<Integer> redList = new ArrayList<>();
            for (int j = 0; j < 6; j++) {
                redList.add(RandomUtil.randomInt(0, 10));
            }

            String left = redList.stream().map(String::valueOf).collect(Collectors.joining(","));

            //String reds = String.join(",", redList);
//            map.put("l",reds);
//            map.put("r", String.valueOf(RandomUtil.randomInt(0, 15)));
            result.add(RandomNumberVO.builder().left(left).right(String.valueOf(RandomUtil.randomInt(0, 15))).build());
        }

        return result;
    }

    public List<RandomNumberVO> randomDLT(int number) {
        List<RandomNumberVO> result = new ArrayList<>();
        for (int i = 0; i < number; i++) {
            List<Integer> redList = new ArrayList<>();
            for (int j = 0; j < 5; j++) {
                Integer red = RandomUtil.randomInt(1, 36);
                if (redList.contains(red)){
                    //System.out.println("重复了");
                    j--;
                    continue;
                }
                redList.add(red);
            }
            Collections.sort(redList);

            String left = redList.stream().map(String::valueOf).collect(Collectors.joining(","));

            //String reds = String.join(",", redList);
//            map.put("l",reds);
//            map.put("r", String.valueOf(RandomUtil.randomInt(1, 13)));
            result.add(RandomNumberVO.builder().left(left).right(String.valueOf(RandomUtil.randomInt(1, 13))).build());
        }

        return result;
    }

    public List<RandomNumberVO> randomSSQ(int number) {
        List<RandomNumberVO> result = new ArrayList<>();
        for (int i = 0; i < number; i++) {
            //Map<String,String> map = new HashMap<>();
            List<Integer> redList = new ArrayList<>();
            for (int j = 0; j < 6; j++) {
                Integer red = RandomUtil.randomInt(1, 34);
                if (redList.contains(red)){
                    //System.out.println("重复了");
                    j--;
                    continue;
                }
                redList.add(red);
            }
            Collections.sort(redList);

            String left = redList.stream().map(String::valueOf).collect(Collectors.joining(","));

            //String reds = String.join(",", redList);
//            map.put("l",reds);
//            map.put("r", String.valueOf(RandomUtil.randomInt(1, 17)));
            result.add(RandomNumberVO.builder().left(left).right(String.valueOf(RandomUtil.randomInt(1, 17))).build());
        }

        return result;
    }

}
